package org.posta.mail.server;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.subethamail.smtp.MessageListener;
import org.subethamail.smtp.server.SMTPServer;

import com.google.inject.Inject;
import com.google.inject.Singleton;

@Singleton
public class MailServer
{
    
    private static Logger log = LoggerFactory.getLogger(MailServer.class);
    
    private int           port;
    
    private SMTPServer    server;
    
    @Inject
    public MailServer(MessageHandler handler)
    {
        port = 2500;
        List<MessageListener> listeners = new ArrayList<MessageListener>();
        listeners.add(handler);
        
        server = new SMTPServer(listeners);
        server.setPort(port);
    }
    
    void start()
    {
        server.start();
        log.info("Started Mail Server");
    }
    
    void stop()
    {
        server.stop();
        log.info("Stopped Mail Server");
    }
    
}
